#include <cstdio>
#include <vector>
#include <memory.h>

using namespace std;

int s[ 20001 ], f[ 20001 ];
bool ok[ 20001 ], visit[ 20001 ];
vector<int> a;
int n, m, c, p;

int find( int root )
{
    if ( s[ root ] == -1 )
        return root;
    return s[ root ] = find( s[ root ] );
}

void merge( int root1, int root2 )
{
    root1 = find( root1 );
    root2 = find( root2 );
    if ( root1 != root2 )
    {
        f[ root2 ] += f[ root1 ];
        ok[ root2 ] |= ok[ root1 ];
        s[ root1 ] = root2;
    }
}

void init( )
{
    int i, t;
    scanf("%d%d%d%d", &n, &m, &c, &p);
    memset( ok, 0, sizeof( ok ) );
    for ( i = 0; i < n; i++ )
    {
        s[ i ] = -1;
        f[ i ] = 1;
    }
    for ( i = 0; i < c; i++ )
    {
        scanf("%d", &t);
        f[ t ] = 0;
        ok[ t ] = true;
    }
    a.clear( );
}

void work( )
{
    int i, u, v, ans = 0;
    memset( visit, 0, sizeof( visit ) );
    for ( i = 0; i < m; i++ )
    {
        scanf("%d%d", &u, &v);
        if ( u == p )
            a.push_back( v );
        else if ( v == p )
            a.push_back( u );
        else
            merge( u, v );
    }
    for ( i = 0; i < a.size( ); i++ )
    {
        u = find( a[ i ] );
        if ( !ok[ u ] && !visit[ u ] )
        {
            visit[ u ] = true;
            ans += f[ u ];
        }
    }
    printf("%d\n", ans);
}

int main( )
{
    int t;
    scanf("%d", &t);
    while ( t-- )
    {
        init( );
        work( );
    }
    return 0;
}
